package com.usian.user.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.user.UserRelationControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.user.dtos.UserRelationDto;
import com.usian.model.user.pojos.ApUserFollow;
import com.usian.user.service.impl.UserRelationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/user")
public class UserRelationController implements UserRelationControllerApi {

    @Autowired
    private UserRelationServiceImpl apUserRelationService;

    @Override
    @PostMapping("/user_follow")
    public ResponseResult follow(@RequestBody UserRelationDto dto){
        return apUserRelationService.follow(dto);
    }

    @PostMapping("/getFollow/{userId}/{followId}")
    public ApUserFollow getFollow(@PathVariable Integer userId, @PathVariable Integer followId){
        if (userId == null || followId == null){
            System.out.println("参数不够");
            return null;
        }
        ApUserFollow one = apUserRelationService.getOne(Wrappers.<ApUserFollow>lambdaQuery().eq(ApUserFollow::getFollowId, followId).eq(ApUserFollow::getUserId, userId));
        return one;
    }
}
